<template>
  <div class="custom-person-info">
    <el-input
      v-model="cardId"
      :placeholder="`输入${element.options.cardName}号`"
      @blur="handleOnBlur"
      @focus="handleOnFocus"
    ></el-input>
    <div v-if="cardId" style="margin-top: 10px">
      姓名：<el-input disabled v-model="name"></el-input>
      <el-divider></el-divider>
      性别：<el-input disabled v-model="sex"></el-input>
    </div>
  </div>
</template>
<script>
export default {
  name: "renderer",
  props: [
    "value",
    "element",
    "models",
    "rules",
    "remote",
    "edit",
    "remoteOptionSource",
    "platform",
    "preview",
    "containerKey",
    "dataSourceValue",
    "eventFunction",
    "printRead",
    "displayFields",
  ],
  computed: {
    // 不可编辑
    disabled() {
      return this.printRead || !this.edit || this.element.options.disabled;
    },
  },
  watch: {
    value(val) {
      this.dataModel = val;
    },
    dataModel(val) {
      this.$emit("input", val);
    },
  },
  data() {
    return {
      cardId: "",
      dataModel: {
        cardId: "",
        name: "",
        sex: "",
      },
    };
  },
  created() {
    this.dataModel = this.value || {
      cardId: "",
      name: "",
      sex: "",
    };
  },
  methods: {
    handleOnFocus() {
      if (this.element.events && this.element.events.onFocus) {
        const funcKey = this.element.events.onFocus;
        if (this.isTable && this.tableName) {
          this.eventFunction[funcKey] &&
            this.eventFunction[funcKey]({
              field: this.element.model,
              table: this.tableName,
              rowIndex: this.rowIndex,
            });
        } else {
          this.eventFunction[funcKey] &&
            this.eventFunction[funcKey]({ field: this.element.model });
        }
      }
    },
    handleOnBlur() {
      if (this.element.events && this.element.events.onBlur) {
        const funcKey = this.element.events.onBlur;
        if (this.isTable && this.tableName) {
          this.eventFunction[funcKey] &&
            this.eventFunction[funcKey]({
              field: this.element.model,
              table: this.tableName,
              rowIndex: this.rowIndex,
            });
        } else {
          this.eventFunction[funcKey] &&
            this.eventFunction[funcKey]({ field: this.element.model });
        }
      }
    },
  },
};
</script>

<style scoped lang="scss">
#l-map {
  height: 360px;
  width: 100%;
}

#r-result {
  width: 100%;
}

.Map {
  width: 100%;
  height: 450px;
}
.operate {
  display: flex;
  margin: 10px 0;
  .el-input {
    width: 300px;
    margin-right: 10px;
  }
}
</style>
